﻿<%@ Page Language="C#" MasterPageFile="~/Template.master" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" Title="Untitled Page" %>

<%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    
    <link type="text/css" href="jquery-ui/themes/base/ui.all.css"rel="stylesheet" /> 
	<script type="text/javascript" src="jquery-ui/ui/ui.core.js"></script>
	<script type="text/javascript" src="jquery-ui/ui/ui.datepicker.js"></script>
	<script language = "Javascript">

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

        function echeck(str) {

		        var at="@"
		        var dot="."
		        var lat=str.indexOf(at)
		        var lstr=str.length
		        var ldot=str.indexOf(dot)
		        if (str.indexOf(at)==-1){
		          
		           return false
		        }

		        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		           
		           return false
		        }

		        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		            
		            return false
		        }

		         if (str.indexOf(at,(lat+1))!=-1){
		            
		            return false
		         }

		         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		          
		            return false
		         }

		         if (str.indexOf(dot,(lat+2))==-1){
		            
		            return false
		         }
        		
		         if (str.indexOf(" ")!=-1){
		            
		            return false
		         }

 		         return true					
	        }

        
</script>
	<script type="text/javascript">
	
		$(document).ready( function()
		{
			var checkUser=0;
			var checkEmail=0;
			var checkPass=0;

			$("#ctl00_ContentPlaceHolder1_txtUsername").keyup(function ()
			{
			   
				if($("#ctl00_ContentPlaceHolder1_txtUsername").attr("value")=="")
				{
				    $("#userNameErr").html("");
				    return;
				}
				var st=$("#ctl00_ContentPlaceHolder1_txtUsername").attr("value");
				var ch=" ";
				if(st.indexOf(ch)>=0)
				{
				    $("#userNameErr").html("<span class='style4'>Tên đăng nhập không hợp lệ</span>");
				    checkUser=1;
				    return;
				}
				
				var url = "Controllers/xlCheckUserName.aspx?username=" + $("#ctl00_ContentPlaceHolder1_txtUsername").attr("value") + "&time=" + (new Date()).getTime();
				
				jQuery.get(url, function(data)
				{
					
					if(data == "1")
				    {
				        $("#userNameErr").html("<span class='validMessage'>Tên đăng nhập hợp lệ</span>");
				        checkUser=0;
				    }
					else if(data=="0")
					{ 
					   $("#userNameErr").html("<span class='style4'>Tên đăng nhập này đã được sử dụng</span>");
					   checkUser=1;
					}
				});
			});
			
			$("#ctl00_ContentPlaceHolder1_txtRePassword").blur(function ()
			{
			    var pass=$("#ctl00_ContentPlaceHolder1_txtPassword").attr("value");
			    var rePass=$("#ctl00_ContentPlaceHolder1_txtRePassword").attr("value");
			    if(pass!=rePass)
			    {
			        $("#rePassErr").html("<span class='style4'>Mật khẩu không trùng nhau</span>");
			        checkPass=1;
			    }
			    else if(pass==rePass&&pass!="")
			    {
			        $("#rePassErr").html("<span class='validMessage'>Hợp Lệ</span>");
			        checkPass=0;
			    }
			       
			});
			
			$("#ctl00_ContentPlaceHolder1_txtEmail").blur(function ()
			{
			    var email=$("#ctl00_ContentPlaceHolder1_txtEmail").attr("value");
			    if(email=="")
			        return;
			    if(echeck(email)==true)
			    {
			        $("#emailErr").html("<span class='validMessage'>Hợp lệ</span>");
			        checkEmail=0;
			    }
			    else
			    {
			        $("#emailErr").html("<span class='style4'>Email không hợp lệ</span>");
			        checkEmail=1;
			    }
			});
			$("#ctl00_ContentPlaceHolder1_txtPassword").keyup(function()
			{
			    if($("#ctl00_ContentPlaceHolder1_txtPassword").attr("value")!="")
			    {
			        $("#passErr").html("");
			    }
			});
			$("#ctl00_ContentPlaceHolder1_txtHoTen").keyup(function()
			{
			    if($("#ctl00_ContentPlaceHolder1_txtHoTen").attr("value")!="")
			    {
			        $("#hoTenErr").html("");
			    }
			});
			
	        
			$("#ctl00_ContentPlaceHolder1_btnSubmit").click(function ()
			{
			    var check=0;
			    if($("#ctl00_ContentPlaceHolder1_txtUsername").attr("value")=="")
			    { 
			        $("#userNameErr").html("<span class='style4'>Tên đăng nhập không được để trống</span>");
			        
			        check=1;
			    }
			    if($("#ctl00_ContentPlaceHolder1_txtPassword").attr("value")=="")
			    { 
			        $("#passErr").html("<span class='style4'>Bạn chưa nhập mật khẩu</span>");
			        
			        check=1;
			    }
			    if($("#ctl00_ContentPlaceHolder1_txtEmail").attr("value")=="")
			    { 
			        $("#emailErr").html("<span class='style4'>Email không được để trống</span>");
			        
			        check=1;
			    }
			    if($("#ctl00_ContentPlaceHolder1_txtHoTen").attr("value")=="")
			    { 
			        $("#hoTenErr").html("<span class='style4'>Bạn chưa nhập tên</span>");
			     
			        check=1;
			    }
			    if($("#txtCode").attr("value")=="")
			    { 
			        $("#errCode").html("<span class='style4'>Bạn chưa nhập mã an toàn</span>");
			     
			        check=1;
			    }
			    if(checkUser==1||checkEmail==1||checkPass==1||check==1)
			    {
			        alert("Bạn điền thông tin trong form không hợp lệ");
			        return false;
			    }
			   
			    return true;
			});
			$("#ctl00_ContentPlaceHolder1_btnReset").click(function ()
			{
			    $("#ctl00_ContentPlaceHolder1_txtUsername").attr("value","");
			    $("#ctl00_ContentPlaceHolder1_txtCode").attr("value","");
			    $("#ctl00_ContentPlaceHolder1_txtHoTen").attr("value","");
			    $("#ctl00_ContentPlaceHolder1_txtPassword").attr("value",""); 
			    $("#ctl00_ContentPlaceHolder1_txtEmail").attr("value","");
			    $("#ctl00_ContentPlaceHolder1_txtNgaySinh").attr("value","");  
			    $("#ctl00_ContentPlaceHolder1_txtDiaChi").attr("value","");
			    $("#ctl00_ContentPlaceHolder1_txtDienThoai").attr("value","");
			    $("#ctl00_ContentPlaceHolder1_txtRePassword").attr("value","");
			    
			    $("#userNameErr").html("");
			    $("#passErr").html("");
			    $("#emailErr").html("");
			     $("#hoTenErr").html("");
			     $("#errCode").html("");
			     $("#rePassErr").html("");
			    return false;
			});
		});
		$(function() 
			{
		        $("#ctl00_ContentPlaceHolder1_txtNgaySinh").datepicker(
		        {
		            changeMonth: true,
			        changeYear: true
			    });
	        });
		
	</script>
        <form action="KetQuaDangNhap.aspx"  method="post" name="frmRegister" id="frmRegister">
                     <br />
                     <br />
                     <table style="font-weight:bold; width: 320px;" border="0" align="center" 
                         cellpadding="4" cellspacing="0">
                      <tr align="center">
                        <td colspan="2" class="table_header">Đăng ký</td>
                        </tr>
                      <tr>
                        <td>Tên đăng nhập:</td>
                        <td ><asp:TextBox runat="server" name="txtUsername"  ID="txtUsername" class="textfield"></asp:TextBox>
                          <span class="style4">*</span><br />
                          <div id="userNameErr"></div>
                        </td>
                      </tr>
                      <tr>
                        <td>Mật khẩu:</td>
                        <td ><asp:TextBox TextMode="Password" runat="server" name="txtPassword" ID="txtPassword" class="textfield"></asp:TextBox>
                          <span class="style4">*</span><br />
                          <div id="passErr"></div>
                        </td>
                      </tr>
                      <tr>
                        <td>Xác nhận mật khẩu:</td>
                        <td ><asp:TextBox TextMode="Password" runat="server" name="txtRePassword" ID="txtRePassword" class="textfield"></asp:TextBox>
                          <span class="style4">*</span><br />
                          <div id="rePassErr"></div>
                        </td>
                      </tr>
                       <tr>
                        <td>Email:</td>
                        <td ><asp:TextBox runat="server" name="txtEmail" ID="txtEmail" class="textfield"></asp:TextBox>
                          <span class="style4">*</span><br />
                          <div id="emailErr"></div>
                        </td>
                      </tr>
                      <tr>
                        <td>Họ tên:</td>
                        <td ><asp:TextBox runat="server" name="txtHoTen" ID="txtHoTen" class="textfield"></asp:TextBox>
                          <span class="style4">*</span><br />
                          <div id="hoTenErr"></div>
                        </td>
                      </tr>
                      <tr>
                        <td>Ngày sinh:</td>
                        <td ><asp:TextBox runat="server" name="txtNgaySinh" ID="txtNgaySinh" class="textfield"></asp:TextBox>
                        </td>
                      </tr>
                       
                      <tr>
                        <td>Địa chỉ:</td>
                        <td ><asp:TextBox runat="server" name="txtDiaChi" ID="txtDiaChi" class="textfield"></asp:TextBox>
                        </td>
                      </tr>
                      <tr>
                        <td>Điện thoại:</td>
                        <td ><asp:TextBox runat="server" name="txtDienThoai" ID="txtDienThoai" class="textfield"></asp:TextBox>
                        </td>
                      </tr>
                      
                      <tr><td>Mã An Toàn:</td><td><cc1:CaptchaControl ID="sercureCode" runat="server" /></td></tr>
                      <tr>
                            <td>
                            Xác nhận lại mã:
                            </td>
                            <td>
                            <asp:TextBox runat="server" name="txtCode" ID="txtCode" class="textfield"></asp:TextBox>
                            <span class="style4">*</span><br />
                            <div id="errCode"></div>
                                <asp:CustomValidator ID="failCode" runat="server" 
                                    ErrorMessage="Mã an toàn không chính xác." Display="Dynamic"></asp:CustomValidator>
                                
                            </td>
                      </tr>
                      <tr>
                        <td></td>
                        <td ><asp:Button runat="server" ID="btnSubmit" UseSubmitBehavior="true" 
                                Text="Đăng ký" onclick="btnSubmit_Click" />&nbsp;<asp:Button runat="server" ID="btnReset" Text="Reset" /></td>
                      </tr>
                         
                    </table></form>
</asp:Content>
